//
//  SportReportViewController.m
//  CoolTennisBall
//
//  Created by 谢伟康 on 15/12/18.
//  Copyright © 2015年 CoolLang. All rights reserved.
//

#import "SportReportViewController.h"
#import "ReportTableViewCell.h"
#import "PNChart.h"
#import "SweetSectionViewController.h"
#import "SportDetailReportModel.h"
#import "NSBundle+CurrentLanguage.h"
#import "UITableView+FDTemplateLayoutCell.h"

@interface SportReportViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *circleView;
@property (strong, nonatomic) PNCircleChart *pnCircleView;
@property (weak, nonatomic) IBOutlet UICountingLabel *pointLabel;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong,nonatomic) SportDetailReportModel *detailReportModel;

@property (weak, nonatomic) IBOutlet UICountingLabel *scoreUnitLabel;
@property (weak, nonatomic) IBOutlet UILabel *scoreDescriptionLabel;

@end

@implementation SportReportViewController

#pragma mark - ViewLifeCircle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configureLocalization];
    [self configureTableView];
    [self configureUI:nil];
    
}

#pragma mark - Localization

- (void)configureLocalization
{
    self.title = NSLocalizedString(@"Report", nil);
    
    self.scoreUnitLabel.text = NSLocalizedString(@"Report.Unit.Points", nil);
    self.scoreDescriptionLabel.text = NSLocalizedString(@"Motor Score", nil);
}

#pragma mark - IBAction

- (IBAction)clickCircleButton:(id)sender {
    SweetSectionViewController *sweetVC = [[SweetSectionViewController alloc] init];
    sweetVC.shoot = self.detailReportModel.speedPercent;
    sweetVC.vatility = self.detailReportModel.durationPercent;
    sweetVC.strong = self.detailReportModel.hitPercent;

    [sweetVC presentInParentViewController:self animationType:DetailViewControllerPresentAnimationTypePop];
}

#pragma mark - Public Method

- (void)configureUI:(SportDetailReportModel *)detailReportModel
{
    self.detailReportModel = detailReportModel;
    [self configureCircleView];
    [self.tableView reloadData];
}

#pragma mark - Private Method

- (void)configureCircleView
{
    if (self.pnCircleView != nil) {
        [self.pnCircleView removeFromSuperview];
    }
//    self.pnCircleView = [[PNCircleChart alloc] initWithFrame:self.circleView.bounds total:@100 current:@(self.detailReportModel.totalScore) clockwise:YES shadow:YES shadowColor:[UIColor colorWithHex:0xf2f2f2]];
        self.pnCircleView = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 0, 200, 200) total:@100 current:@(self.detailReportModel.totalScore) clockwise:YES shadow:YES shadowColor:[UIColor colorWithHex:0xf2f2f2]];
    self.pnCircleView.strokeColor = [UIColor colorWithHex:0xffd246];
    self.pnCircleView.strokeColorGradientMiddle = [UIColor colorWithHex:0xfa5d4c];
    self.pnCircleView.strokeColorGradientStart = [UIColor colorWithHex:0xf8296b];
    self.pnCircleView.lineWidth = @10;
    self.pnCircleView.countingLabel.hidden = YES;
    [self.circleView addSubview:self.pnCircleView];
    [self.pnCircleView strokeChart];
    
    self.pointLabel.format = @"%d";
    [self.pointLabel countFrom:0 to:self.detailReportModel.totalScore withDuration:1];
}

- (void)configureTableView
{
    [self.tableView registerNib:[UINib nibWithNibName:@"ReportTableViewCell" bundle:nil] forCellReuseIdentifier:@"ReportTableViewCell"];
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.estimatedRowHeight = 76;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.detailReportModel.detailDesArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ReportTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReportTableViewCell"];
    SportDetailItemModel *item = self.detailReportModel.detailDesArray[indexPath.row];
    [cell configureModel:item atIndexPath:indexPath];
    
    return cell;
}

#pragma mark - UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [tableView fd_heightForCellWithIdentifier:@"ReportTableViewCell" cacheByIndexPath:indexPath configuration:^(ReportTableViewCell *cell) {
        SportDetailItemModel *item = self.detailReportModel.detailDesArray[indexPath.row];
        [cell configureModel:item atIndexPath:indexPath];
    }];
}


@end
